package org.third.common.domain;

import java.util.Date;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.third.common.domain.entity.DeploymentStatus;

@Entity
@Table(name = "deployment")
public class Deployment {

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "id")
	private Long id;

	@Column(name = "uuid", nullable = false, length = 50, unique = true)
	private String uuid;
	
	@Column(name = "deployment_status", nullable = false)
	@Enumerated(EnumType.STRING)
	private DeploymentStatus status;

	@Column(name = "create_time", nullable = false, updatable=false)
	@Temporal(TemporalType.TIMESTAMP)
	private Date createTime;
	
	@Column(name = "update_time")
	@Temporal(TemporalType.TIMESTAMP)
	private Date updatedTime;
	
	@Column(name = "updates", nullable = false)
	private Long updates;
	
//	@OneToOne(cascade=CascadeType.ALL, mappedBy="deployment")
//	private Feature feature;
//	
//	@OneToOne(cascade=CascadeType.ALL, mappedBy="deployment")
//	private SuiteConfigurationPod suiteConfigurationPod;
//	
//	@OneToOne(cascade=CascadeType.ALL, mappedBy="deployment")
//	private SuiteReconfiguration suiteReconfiguration;
//	
//	@OneToMany(cascade=CascadeType.ALL,fetch = FetchType.LAZY, mappedBy="deployment")
//	private Set<SuiteInstallation> suiteInstallations;
//	
//	@OneToMany(cascade = CascadeType.ALL,fetch = FetchType.LAZY, mappedBy="deployment")
//	private Set<SuiteUpgrades> SuiteUpgrades;
//
//	@OneToMany(cascade=CascadeType.ALL,fetch = FetchType.LAZY, mappedBy="deployment")
//	private  Set<DeployFeatureHistory> deployFeatureHistory;
	
//	@OneToMany(cascade=CascadeType.ALL, mappedBy="deployment")
//	private Set<SuiteUpgrades> SuiteUpgrades;
	
	@PrePersist
	protected void onCreate() {
		createTime = updatedTime = new Date();
		updates = 0L;
	}

    @PreUpdate
    protected void onUpdate() {
    	updatedTime = new Date();
    	updates = updates + 1L;
    }

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getUuid() {
		return uuid;
	}

	public void setUuid(String uuid) {
		this.uuid = uuid;
	}

	public DeploymentStatus getStatus() {
		return status;
	}

	public void setStatus(DeploymentStatus status) {
		this.status = status;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Date getUpdatedTime() {
		return updatedTime;
	}

	public void setUpdatedTime(Date updatedTime) {
		this.updatedTime = updatedTime;
	}

	public Long getUpdates() {
		return updates;
	}

	public void setUpdates(Long updates) {
		this.updates = updates;
	}

//	public Feature getFeature() {
//		return feature;
//	}
//
//	public void setFeature(Feature feature) {
//		this.feature = feature;
//	}
//
//	public SuiteConfigurationPod getSuiteConfigurationPod() {
//		return suiteConfigurationPod;
//	}
//
//	public void setSuiteConfigurationPod(SuiteConfigurationPod suiteConfigurationPod) {
//		this.suiteConfigurationPod = suiteConfigurationPod;
//	}
//
//	public Set<SuiteInstallation> getSuiteInstallations() {
//		return suiteInstallations;
//	}
//
//	public void setSuiteInstallations(Set<SuiteInstallation> suiteInstallations) {
//		this.suiteInstallations = suiteInstallations;
//	}
//
//	public SuiteReconfiguration getSuiteReconfiguration() {
//		return suiteReconfiguration;
//	}
//
//	public void setSuiteReconfiguration(SuiteReconfiguration suiteReconfiguration) {
//		this.suiteReconfiguration = suiteReconfiguration;
//	}
//
//	public Set<SuiteUpgrades> getSuiteUpgrades() {
//		return SuiteUpgrades;
//	}
//
//	public void setSuiteUpgrades(Set<SuiteUpgrades> suiteUpgrades) {
//		SuiteUpgrades = suiteUpgrades;
//	}
//
//	public Set<DeployFeatureHistory> getDeployFeatureHistory() {
//		return deployFeatureHistory;
//	}
//
//	public void setDeployFeatureHistory(Set<DeployFeatureHistory> deployFeatureHistory) {
//		this.deployFeatureHistory = deployFeatureHistory;
//	}
}